package exer;

/**
 * @author shkstart
 * @create 2022-08-14-23:34
 */
public class Num234 {
    public boolean isPalindrome(ListNode head) {

        if (head == null || head.next == null) {
            return false;
        }
        ListNode mid = midListNode(head);
        ListNode turn = turn(mid);
        while (head != null && turn != null) {
            if (head.val != turn.val) {
                return false;
            }
            head = head.next;
            turn = turn.next;
        }
        return true;


    }
    public ListNode midListNode(ListNode head){

        ListNode low = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            low = low.next;
            fast = fast.next.next;
        }
        return low;


    }
    public ListNode turn(ListNode head){

        ListNode perv = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = perv;
            perv = cur;
            cur = next;
        }
        return  perv;
    }
}
